home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / fromdl / fromdll.frm < prev    next >
Text File  |  1995-01-19  |  5KB  |  200 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "From a DLL"
  5.    ClientHeight    =   5700
  6.    ClientLeft      =   1125
  7.    ClientTop       =   2715
  8.    ClientWidth     =   7245
  9.    Height          =   6105
  10.    Icon            =   FROMDLL.FRX:0000
  11.    Left            =   1065
  12.    LinkTopic       =   "Form1"
  13.    ScaleHeight     =   5700
  14.    ScaleWidth      =   7245
  15.    Top             =   2370
  16.    Width           =   7365
  17.    Begin PictureBox Picture2 
  18.       Height          =   2895
  19.       Left            =   3720
  20.       ScaleHeight     =   2865
  21.       ScaleWidth      =   3405
  22.       TabIndex        =   8
  23.       Top             =   2460
  24.       Width           =   3435
  25.    End
  26.    Begin CommandButton btnClearPic 
  27.       Caption         =   "Clear Picture"
  28.       Height          =   495
  29.       Left            =   1980
  30.       TabIndex        =   7
  31.       Top             =   1860
  32.       Width           =   1695
  33.    End
  34.    Begin CommandButton btnPic 
  35.       Caption         =   "Load &Picture"
  36.       Height          =   495
  37.       Left            =   180
  38.       TabIndex        =   6
  39.       Top             =   1860
  40.       Width           =   1695
  41.    End
  42.    Begin PictureBox Picture1 
  43.       AutoRedraw      =   -1  'True
  44.       Height          =   2895
  45.       Left            =   180
  46.       ScaleHeight     =   191
  47.       ScaleMode       =   3  'Pixel
  48.       ScaleWidth      =   227
  49.       TabIndex        =   5
  50.       Top             =   2460
  51.       Width           =   3435
  52.    End
  53.    Begin CommandButton btnCallDll 
  54.       Caption         =   "Call DLL"
  55.       Height          =   495
  56.       Left            =   180
  57.       TabIndex        =   4
  58.       Top             =   1200
  59.       Width           =   1695
  60.    End
  61.    Begin CommandButton btnStr2 
  62.       Caption         =   "String 2"
  63.       Height          =   495
  64.       Left            =   1980
  65.       TabIndex        =   3
  66.       Top             =   600
  67.       Width           =   1695
  68.    End
  69.    Begin CommandButton btnStr1 
  70.       Caption         =   "String 1"
  71.       Height          =   495
  72.       Left            =   180
  73.       TabIndex        =   2
  74.       Top             =   600
  75.       Width           =   1695
  76.    End
  77.    Begin TextBox Text1 
  78.       Height          =   285
  79.       Left            =   180
  80.       TabIndex        =   1
  81.       Top             =   180
  82.       Width           =   6975
  83.    End
  84.    Begin CommandButton btnExit 
  85.       Caption         =   "E&xit"
  86.       Height          =   495
  87.       Left            =   5880
  88.       TabIndex        =   0
  89.       Top             =   1200
  90.       Width           =   1215
  91.    End
  92.    Begin Label Label2 
  93.       AutoSize        =   -1  'True
  94.       BackStyle       =   0  'Transparent
  95.       Caption         =   "Copied from other Picture"
  96.       Height          =   195
  97.       Left            =   3720
  98.       TabIndex        =   10
  99.       Top             =   5400
  100.       Width           =   2175
  101.    End
  102.    Begin Label Label1 
  103.       AutoSize        =   -1  'True
  104.       BackStyle       =   0  'Transparent
  105.       Caption         =   "Loaded from DLL"
  106.       Height          =   195
  107.       Left            =   180
  108.       TabIndex        =   9
  109.       Top             =   5400
  110.       Width           =   1470
  111.    End
  112. End
  113. Option Explicit
  114.  
  115. Sub btnCallDll_Click ()
  116.  
  117. Dim r%
  118.  
  119. r% = SayHi()
  120.  
  121. End Sub
  122.  
  123. Sub btnClearPic_Click ()
  124. picture2.Picture = LoadPicture()
  125. picture1.Picture = LoadPicture()
  126. End Sub
  127.  
  128. Sub btnExit_Click ()
  129.  
  130. FreeLibrary (DLLID%)
  131.  
  132. End
  133. End Sub
  134.  
  135. Sub btnPic_Click ()
  136.  
  137. Dim hMyBitmap%, hdcmemory%
  138. Dim r%, dccontrol%, cx%, cy%, pict1%
  139.  
  140. picture1.ScaleMode = 3
  141.  
  142. dccontrol% = picture1.hDC
  143. cx% = picture1.ScaleWidth
  144. cy% = picture1.ScaleHeight
  145.  
  146. ' load bitmap from DLL
  147. hMyBitmap% = LoadBitmap(DLLID%, "CPARROW")
  148.  
  149. ' Create context compatible with the picture box
  150. hdcmemory% = CreateCompatibleDC(dccontrol%)
  151. ' select bitmap into device context
  152. r% = SelectObject(hdcmemory%, hMyBitmap%)
  153.  
  154. ' Copy it
  155. r% = BitBlt(dccontrol%, 0, 0, cx%, cy%, hdcmemory%, 0, 0, SRCCOPY)
  156.  
  157. picture1.Picture = picture1.Image ' move presistent image to visible
  158. picture2.Picture = picture1.Picture ' prove it can be moved
  159.  
  160. r% = DeleteDC(hdcmemory%)      ' delete device context
  161. r% = DeleteObject(hMyBitmap%)  ' delete object (free memory!)
  162.  
  163. End Sub
  164.  
  165. Sub btnStr1_Click ()
  166.  
  167. Dim temp$, r%
  168.  
  169. temp$ = Space(80)
  170.  
  171. r% = LoadString(DLLID%, 1, temp$, Len(temp$))
  172.  
  173. text1 = Trim(temp$)
  174.  
  175. End Sub
  176.  
  177. Sub btnStr2_Click ()
  178.  
  179. Dim temp$, r%
  180.  
  181. temp$ = Space(80)
  182.  
  183. r% = LoadString(DLLID%, 2, temp$, Len(temp$))
  184.  
  185. text1 = Trim(temp$)
  186.  
  187. End Sub
  188.  
  189. Sub Form_Load ()
  190.  
  191. DLLID% = LoadLibrary("TEST.DLL")
  192. If DLLID% < 32 Then
  193.     MsgBox "Error loading DLL"
  194.     End
  195. End If
  196.  
  197.  
  198. End Sub
  199.  
  200.